package impl

import (
	"jupiter-demo/internal/app/model/dao"
	"jupiter-demo/internal/app/model/db"
	"jupiter-demo/pkg/util"
	"time"
)


type UserResponse struct {
   num  []int
}
func (m *mysqlImpl)Get(id int) (user db.User,err error){
	user = db.User{}
	err = m.gh.Where("id = ?", id).Find(&user).Error
	return
}

func (m *mysqlImpl)GetUser(id int)(user db.User){

	return dao.InitUser(m.gh).GetUserByUID(id)
}

func (m *mysqlImpl)GetUserLoginTime()(userResponse UserResponse,err error )  {
     timelist := make(map[string][]time.Time,2)
     timelist["今日"]=make([]time.Time,2)
	 timelist["昨日"]=make([]time.Time,2)
	 timelist["今日"] = append(timelist["今日"],util.Todaystart())
	 timelist["今日"] = append(timelist["今日"],util.Todayend())
	 timelist["昨日"] = append(timelist["昨日"],util.Yesterdaystart())
	 timelist["昨日"] = append(timelist["昨日"],util.Yesterdayend())

	 for _,v := range timelist{
	 	 count ,err :=  dao.InitUserinfo(m.gh).GetLoginTimeNum(v[0],v[1])
	 	 if err != nil{
	 	 	return UserResponse{nil},err
		 }
		 userResponse.num = append(userResponse.num,count)

	 }
   return  userResponse,nil
}





